# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=rrdtool
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.9.0
pkgrel=1
pkgdesc="Round Robin Database (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://oss.oetiker.ch/rrdtool/'
msys2_references=(
  "cpe: cpe:/a:rrdtool_project:rrdtool"
)
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
source=("https://github.com/oetiker/rrdtool-1.x/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('5e65385e51f4a7c4b42aa09566396c20e7e1a0a30c272d569ed029a81656e56b')

prepare() {
  cp -Rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}
  ./bootstrap
}

build() {
  cd "${srcdir}"/build-${MSYSTEM}

  # Do not add --host and --target options, otherwise
  # executables are installed with target triplet prefixes
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --enable-static \
    --disable-shared \
    --disable-tcl \
    --disable-python \
    --disable-docs \
    --disable-nls \
    --disable-perl \
    --disable-mmap \
    --disable-ruby \
    --disable-rrdcached

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYRIGHT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
